package com.dominator.repository;

import com.dominFramework.core.dao.SqlDao;
import com.dominFramework.core.id.SystemIdUtils;
import com.dominFramework.core.typewrap.Dto;
import com.dominFramework.core.typewrap.Dtos;
import com.dominator.mybatis.dao.T_account_red_packetDao;
import com.dominator.mybatis.dao.T_account_red_packetPO;
import com.dominator.utils.dao.JdbcHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

@Repository
public class DaoAccountRedPacket {
    @Resource
    JdbcHelper jh;

    @Autowired
    T_account_red_packetDao accountRedPacketDao;

    @Autowired
    SqlDao sqlDao;

    /**
     * 添加
     *
     * @param record
     * @return
     */
    public Integer insertSelective(T_account_red_packetPO record) {
        return accountRedPacketDao.insert(record);
    }

    /**
     * 删除
     *
     * @param
     * @return
     */
    public Integer deleteByPrimaryKey(String id) {
        return accountRedPacketDao.deleteByKey(id);
    }

    /**
     * 修改
     *
     * @param record
     * @return
     */
    public Integer updateByPrimaryKey(T_account_red_packetPO record) {
        return accountRedPacketDao.updateByKey(record);
    }

    /**
     * 查询单条记录
     *
     * @param id
     * @return
     */
    public T_account_red_packetPO selectByPrimaryKey(String id) {
        T_account_red_packetPO row = accountRedPacketDao.selectByKey(id);
        return row;
    }


    /**
     * 添加红包
     *
     * @param
     * @return
     */
    public Integer add(String userId, BigDecimal money) {
        T_account_red_packetPO redPacketPO = new T_account_red_packetPO();
        redPacketPO.setId(SystemIdUtils.uuid());
        redPacketPO.setUser_id(userId);
        redPacketPO.setMoney(money);
        redPacketPO.setCreate_time(new Date());
        redPacketPO.setIs_valid("1");
        return accountRedPacketDao.insert(redPacketPO);
    }

    /**
     * 通过用户id查询账户
     *
     * @param
     * @return
     */
    public List<Dto> selectByUserId(String userId) {
        Dto qDto = Dtos.newDto("userId", userId);
        List<Dto> list = sqlDao.list("AccountRedPacket.selectByUserId", qDto);
        return list;
    }


}
